'use strict';

/* Controllers */
  // signin controller
app.controller('SigninFormController', ['$scope','$rootScope', '$http', '$state', function($scope,$rootScope, $http, $state) {
    $scope.user = {};
    $scope.authError = null;
    $scope.login = function() {
      $scope.authError = null;
      // Try to login
      $http.post('/system-boot/sys/user/login.json', {email: $scope.user.email, password: $scope.user.password})
      .then(function(response) {
        if (!response.data.success) {
          
          $scope.authError = response.data.errorMessage;
        }else{
          $rootScope.user = response.data.data;
          $state.go('app.dashboard');
        }
      }, function(x) {
        $scope.authError = 'Server Error';
      });
    };
  }]);
